using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reactive.Concurrency;
using System.Threading;

namespace Koans.Lessons
{
    [TestClass]
    public class WriteYourOwnLesson
    {
        /*
         * Find something we missed?
         * Write it here, and email it to isidore@setgame.com 
         */


        [TestMethod]
        public void TheMissingLesson()
        {
            int count = 5;
            object wait = null;
            DateTime assertser = DateTime.Now;
            string msg = "";
            Action<Action<DateTimeOffset>> action = (Action<DateTimeOffset> self) => 
            {
                msg += string.Format("{0} > {1} |", DateTime.Now, assertser);
                Assert.IsTrue(DateTime.Now > assertser);
                if (count-- != 0)
                {
                    assertser = DateTime.Now;
                    self(DateTime.Now.AddSeconds(2));
                }
                else
                    wait = new object();
            };

            Scheduler.NewThread.Schedule(DateTime.Now.AddSeconds(5), action);
            while (wait == null)
            {
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
            Assert.IsNotNull(wait);
            Assert.Inconclusive(msg);            
        }

        public object ___ = "Please Fill in the blank";
        public int ____ = 100;
    }
}